<template>
    <div>
        <mu-paper :z-depth="1" class="demo-list-wrap">
  <mu-list textline="two-line">
    <mu-list-item v-for="item in list" :key="item.user_id" avatar button :ripple="false">
      <mu-list-item-action>
        <mu-avatar>
          <img :src="item.user_photo">
        </mu-avatar>
      </mu-list-item-action>
      <mu-list-item-content>
        <mu-list-item-title>{{item.user_name}}</mu-list-item-title>
        <mu-list-item-sub-title>{{item.user_number}}</mu-list-item-sub-title>
      </mu-list-item-content>
      <mu-list-item-action>
        <mu-button @click="passpwd" v-if="id === item.user_id" flat color="primary">修改密码</mu-button>
        <p>--</p>
      </mu-list-item-action>
    </mu-list-item>
  </mu-list>
</mu-paper>
<mu-container>
  <mu-dialog title="是否确认修改密码？" width="600" max-width="80%" :esc-press-close="false" :overlay-close="false" :open.sync="openAlert">
      <mu-text-field v-model="commitess" prop="pwd"></mu-text-field>
    <mu-button slot="actions" flat color="primary" @click="AlertDialog">确认</mu-button>
    <mu-button slot="actions" flat color="primary" @click="closeAlertDialog">取消</mu-button>
  </mu-dialog>
</mu-container>
    </div>
</template>
<script>
export default {
    data () {
        return {
            list:[],
            id: '',
            commitess: '',
            openAlert: false
        }
    },
    mounted () {
        this.id = JSON.parse(window.sessionStorage.userInfo).user_id
        console.log('id', this.id)
        this.listimg()
    },
    methods: {
        listimg () {
            this.$axios.get('/userImg').then(res => {
                if (res.status === 1) {
                    console.log(res.database)
                    this.list = res.database
                }
            })
        },
        passpwd (val) {
            this.openAlert = true
            
        },
        closeAlertDialog () {
            this.openAlert = false
        },
        AlertDialog () {
            this.$axios.post('/passwd', {
                id:this.id,
                commits: this.commitess
            }).then(res=> {
                if (res.status === 1) {
                    this.$toast.success({
                        position: 'top',
                        message: '修改密码成功'
                    });
                    this.openAlert = false
                    this.$router.push('/login')
                } else {
                    this.$toast.error({
                        position: 'top',
                        message: '修改密码失败'
                    });
                }
            })
        }
    }
}
</script>
